package com.shrct.businessprocess.project.impl;

import com.google.common.base.Objects;
import com.shrct.businessprocess.project.RCParameterService;
import com.shrct.businessprocess.project.RCParameters;
import com.uniquesoft.uidl.validation.Validates;
import edu.fudan.mylang.pf.BaseService;
import edu.fudan.mylang.pf.IGenericQuery;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.springframework.stereotype.Service;

@Service("com.shrct.businessprocess.project.RCParameterService")
public class RCParameterServiceImpl extends BaseService implements RCParameterService {
  public String getNextProjectId() {
    String _xblockexpression = null;
    {
      RCParameters param = this.getParemeters();
      Integer _projectId = param.getProjectId();
      int _plus = ((_projectId).intValue() + 1);
      param.setProjectId(Integer.valueOf(_plus));
      Integer _projectIdYear = param.getProjectIdYear();
      int _multiply = ((_projectIdYear).intValue() * 1000);
      Integer _projectId_1 = param.getProjectId();
      int _plus_1 = (_multiply + (_projectId_1).intValue());
      String _string = Integer.valueOf(_plus_1).toString();
      _xblockexpression = (_string);
    }
    return _xblockexpression;
  }
  
  public void setProjectYear(final Integer year) {
    boolean _notEquals = (!Objects.equal(year, null));
    Validates.Assert(_notEquals, "\u5FC5\u987B\u8BBE\u7F6E\u5E74\u5EA6");
    RCParameters _paremeters = this.getParemeters();
    final Procedure1<RCParameters> _function = new Procedure1<RCParameters>() {
        public void apply(final RCParameters it) {
          it.setProjectIdYear(year);
          it.setProjectId(Integer.valueOf(0));
        }
      };
    ObjectExtensions.<RCParameters>operator_doubleArrow(_paremeters, _function);
  }
  
  public RCParameters getParemeters() {IGenericQuery<RCParameters> query=getObjectFactory().createGenericQuery(RCParameters.class,"select p from com.shrct.businessprocess.project.impl.RCParametersImpl as p   where  p.active = 1      ");
    RCParameters _uniqueResult = query.uniqueResult();
    return _uniqueResult;
  }
  
  public String getNextOrderId() {
    String _xblockexpression = null;
    {
      RCParameters param = this.getParemeters();
      Integer _orderId = param.getOrderId();
      int _plus = ((_orderId).intValue() + 1);
      param.setOrderId(Integer.valueOf(_plus));
      Integer _orderIdYear = param.getOrderIdYear();
      int _modulo = ((_orderIdYear).intValue() % 100);
      int _multiply = (_modulo * 10000);
      Integer _orderId_1 = param.getOrderId();
      int _plus_1 = (_multiply + (_orderId_1).intValue());
      String _string = Integer.valueOf(_plus_1).toString();
      _xblockexpression = (_string);
    }
    return _xblockexpression;
  }
  
  public void setOrderYear(final Integer year) {
    boolean _notEquals = (!Objects.equal(year, null));
    Validates.Assert(_notEquals, "\u5FC5\u987B\u8BBE\u7F6E\u5E74\u5EA6");
    RCParameters _paremeters = this.getParemeters();
    final Procedure1<RCParameters> _function = new Procedure1<RCParameters>() {
        public void apply(final RCParameters it) {
          it.setOrderIdYear(year);
          it.setOrderId(Integer.valueOf(0));
        }
      };
    ObjectExtensions.<RCParameters>operator_doubleArrow(_paremeters, _function);
  }
  
  /**
   * 需自动编号的设备
   */
  public Integer getNextProductSid() {
    Integer _xblockexpression = null;
    {IGenericQuery<RCParameters> query=getObjectFactory().createGenericQuery(RCParameters.class,"select p from com.shrct.businessprocess.project.impl.RCParametersImpl as p   where  p.active = 1      ");
      RCParameters param = query.uniqueResult();
      Integer _nextProductSid = param.getNextProductSid();
      boolean _equals = Objects.equal(_nextProductSid, null);
      if (_equals) {
        param.setNextProductSid(Integer.valueOf(1));
      } else {
        Integer _nextProductSid_1 = param.getNextProductSid();
        int _plus = ((_nextProductSid_1).intValue() + 1);
        param.setNextProductSid(Integer.valueOf(_plus));
      }
      Integer _nextProductSid_2 = param.getNextProductSid();
      _xblockexpression = (_nextProductSid_2);
    }
    return _xblockexpression;
  }
}
